import { observable, action, autorun, toJS } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';
import { WeaTools } from 'ecCom';
import { message } from 'antd';
import * as Apis from '../apis/crmMessage';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
export class CrmMessageStore {
    title = '';
    @observable messageInfos = [];
    @observable messageInfosTotal = 0;
    @observable customerId = '';
    baseParams = {};

    @observable verified = false;
    @observable hasRight = false; // 权限

    @action
    initDatas =(params = {}) => {
      Apis.getLeaveMessage(params).then((data) => {
        if (!data.hasright && typeof (data.hasright) !== 'undefined') {
          this.hasRight = false;
          this.verified = true;
        } else {
          this.hasRight = true;
          this.verified = true;
          this.messageInfos = data.datas.rsList;
          this.messageInfosTotal = data.datas.totalSize;
          this.customerId = params.customerId;
          this.baseParams = params;
        }
      });
    }

    @action
    getNextLeaveMessage = (params = {}) => {
      Apis.getLeaveMessage({ ...this.baseParams, ...params }).then((data) => {
        this.messageInfos = data.datas.rsList;
        this.messageInfosTotal = data.datas.totalSize;
      });
    }

    saveLeaveMessage=(params) => {
      Apis.saveLeaveMessage(params).then((data) => {
        if (data.status == 'success') {
          this.initDatas({ from: 'mine', customerId: params.customerId });
        } else {
          Modal.error({
            title: getLabel(15172, '系统提示'),
            content: `操作失败,${data.msgcode}`,
          });
        }
      });
    }
}
